package cn.kai.ums.controller;


import cn.kai.ums.mapper.UmsClassCourseTeachMapper;
import cn.kai.ums.model.UmsClassCourseTeach;
import cn.kai.ums.service.UmsClassCourseTeachService;
import cn.kai.ums.tools.JsonData;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("ums/v1/classcoutea")
@Api(tags = "必修课上课信息控制类")
public class ClassCourseTeachController {

    @Autowired
    private UmsClassCourseTeachMapper umsClassCourseTeachMapper;

    @Autowired
    private UmsClassCourseTeachService umsClassCourseTeachService;


    @ApiOperation("根据课程编号，班级编号，教师编号模糊查询")
    @GetMapping
    public JsonData getClassTeaList(@RequestParam(defaultValue = "1",required = false) Integer pageNum
            ,@RequestParam(defaultValue = "5",required = false) Integer pageSize
            ,@RequestParam(defaultValue = "",value = "likeclasstea",required = false) String likeclasstea){

        Page<UmsClassCourseTeach> umsClassCourseTeachPage = umsClassCourseTeachMapper.selectPage(new Page<>(pageNum,pageSize)
                , Wrappers.<UmsClassCourseTeach>lambdaQuery()
                        .like(UmsClassCourseTeach::getClassCourseTeachNo,likeclasstea)
                        .or()
                        .like(UmsClassCourseTeach::getClassCourseTeachClassNo,likeclasstea)
                        .or()
                        .like(UmsClassCourseTeach::getClassCourseTeacherNo,likeclasstea));
        return JsonData.buildSuccess(umsClassCourseTeachPage);
    }

    @PostMapping
    public JsonData saveClassTea(@RequestBody UmsClassCourseTeach umsClassCourseTeach){
        return JsonData.buildSuccess(umsClassCourseTeachService.save(umsClassCourseTeach));
    }

    @PutMapping
    public JsonData updateClassTea(@RequestBody UmsClassCourseTeach umsClassCourseTeach){
        return JsonData.buildSuccess(umsClassCourseTeachService.updateById(umsClassCourseTeach));
    }

    @DeleteMapping
    public JsonData delClassTea(@RequestParam Integer ctid){
        return JsonData.buildSuccess(umsClassCourseTeachService.removeById(ctid));
    }

    @PostMapping("/delBatchTea")
    public JsonData delBatchTea(@RequestBody List<Integer> ctids){
        return JsonData.buildSuccess((umsClassCourseTeachService.removeByIds(ctids)));
    }

}
